package org.game.db.bean;

import static org.game.db.StaticResource.DungeonLevelResource.FK_PINGYING_TABLE_NAMES;
import com.sojoys.artifact.factory.bytebuff.IByteBuff;
import static org.game.db.StaticResource.DungeonLevelResource.SOURCE_COLUMN_REMARKS;
import static org.game.db.StaticResource.DungeonLevelResource.PINGYING_COLUMN_NAMES;
import org.apache.commons.lang3.ArrayUtils;
import java.sql.SQLException;
import static org.game.db.StaticResource.DungeonLevelResource.SOURCE_COLUMN_NAMES;
import com.sojoys.artifact.tools.ToolMap;
import static org.game.db.StaticResource.DungeonLevelResource.HASHCODE_COLUMN_NAMES;
import com.sojoys.artifact.tools.SK_Plus;
import org.game.db.cache.PlayerCache;
import java.sql.ResultSet;
import static org.game.db.StaticResource.DungeonLevelResource.FK_SOURCE_COLUMN_NAMES;
import java.util.Map;
import static org.game.db.StaticResource.DungeonLevelResource.COLUMN_COUNT;
import org.game.db.cache.DungeonLevelCache;
import com.sojoys.artifact.constant.DataModelKeyEnum;
import static org.game.db.StaticResource.DungeonLevelResource.*;
import static org.game.db.StaticResource.DungeonLevelResource.FK_HASHCODE_COLUMN_NAMES;
import static org.game.db.StaticResource.DungeonLevelResource.COLUMN_CLASSTYPES;
import static org.game.db.StaticResource.DungeonLevelResource.COLUMN_BASICTYPES;
import com.sojoys.artifact.build.data.base.BasePojo;
import static org.game.db.StaticResource.DungeonLevelResource.COLUMN_COLUMNTYPES;
import java.util.List;
import com.sojoys.artifact.tools.ToolCopy;
import com.alibaba.fastjson.JSONObject;
import static org.game.db.StaticResource.DungeonLevelResource.FK_PINGYING_COLUMN_NAMES;
import static org.game.db.StaticResource.DungeonLevelResource.FK_SOURCE_TABLE_NAMES;
import static org.game.db.StaticResource.DungeonLevelResource.FK_HASHCODE_TABLE_NAMES;
import static org.game.db.StaticResource.DungeonLevelResource.*;
/**
 * 副本关卡记录
 */
public class DungeonLevel extends BasePojo<DungeonLevel> {
	
	
	/**
	 * 索引值
	 */
	private String[] indexValues = new String[2];
	
	/**
	* id
	*/
	private long id;
	
	/**
	* 玩家id
	*/
	private int playerId;
	
	/**
	* 关卡cid
	*/
	private int cid;
	
	/**
	* 获得星级（最高星级）
	*/
	private int star;
	
	/**
	* create_date
	*/
	private java.util.Date createDate;
	
	/**
	* modified_date
	*/
	private java.util.Date modifiedDate;
	
	/**
	* 当日战斗次数
	*/
	private int fightCount;
	
	/**
	* 是否胜利
	*/
	private boolean win;
	
	/**
	* 达成的目标
	*/
	private List achieveGoals;
	
	/**
	* 副本关卡次数刷新时间
	*/
	private java.util.Date lastRefreshTime;
	
	/**
	* 总战斗次数
	*/
	private int totalFightCount;
	
	
	@Deprecated
	public static DungeonLevel builder() {
		DungeonLevel dungeonLevel = new DungeonLevel();
		return dungeonLevel;
	}
	
	@Deprecated
	public DungeonLevel() {
		super();
	}
	
	public DungeonLevel(long id, int playerId, int cid, int star, int fightCount, boolean win, List achieveGoals, java.util.Date lastRefreshTime, int totalFightCount) {
		super();
		this.id = id;
		this.playerId = playerId;
		this.cid = cid;
		this.star = star;
		this.createDate = new java.util.Date();
		this.modifiedDate = new java.util.Date();
		this.fightCount = fightCount;
		this.win = win;
		this.achieveGoals = achieveGoals;
		this.lastRefreshTime = lastRefreshTime;
		this.totalFightCount = totalFightCount;
	}
	
	/**
	 * id
	 */
	public long getId() {return id;}
	
	/**
	 * id
	 */
	public DungeonLevel setId(long id) {this.id = id;return this;}
	
	/**
	 * 玩家id
	 */
	public int getPlayerId() {return playerId;}
	
	/**
	 * 玩家id
	 */
	public DungeonLevel setPlayerId(int playerId) {this.playerId = playerId;return this;}
	
	/**
	 * 关卡cid
	 */
	public int getCid() {return cid;}
	
	/**
	 * 关卡cid
	 */
	public DungeonLevel setCid(int cid) {this.cid = cid;return this;}
	
	/**
	 * 获得星级（最高星级）
	 */
	public int getStar() {return star;}
	
	/**
	 * 获得星级（最高星级）
	 */
	public DungeonLevel setStar(int star) {this.star = star;return this;}
	
	/**
	 * create_date
	 */
	public java.util.Date getCreateDate() {return createDate;}
	
	/**
	 * create_date
	 */
	protected DungeonLevel setCreateDate(java.util.Date createDate) {this.createDate = createDate;return this;}
	
	/**
	 * modified_date
	 */
	public java.util.Date getModifiedDate() {return modifiedDate;}
	
	/**
	 * modified_date
	 */
	protected DungeonLevel setModifiedDate(java.util.Date modifiedDate) {this.modifiedDate = modifiedDate;return this;}
	
	/**
	 * 当日战斗次数
	 */
	public int getFightCount() {return fightCount;}
	
	/**
	 * 当日战斗次数
	 */
	public DungeonLevel setFightCount(int fightCount) {this.fightCount = fightCount;return this;}
	
	/**
	 * 是否胜利
	 */
	public boolean isWin() {return win;}
	
	/**
	 * 是否胜利
	 */
	public DungeonLevel setWin(boolean win) {this.win = win;return this;}
	
	/**
	 * 达成的目标
	 */
	public List getAchieveGoals() {return achieveGoals;}
	
	/**
	 * 达成的目标
	 */
	public DungeonLevel setAchieveGoals(List achieveGoals) {this.achieveGoals = achieveGoals;return this;}
	
	/**
	 * 达成的目标
	 */
	public byte[] getAchieveGoalsByte() {
		return toBytes(achieveGoals);
	}
	
	/**
	 * 达成的目标
	 */
	public List initAchieveGoalsByte(byte[] _byte) {
		return (List)forBytesObject(_byte);
	}	
	/**
	 * 副本关卡次数刷新时间
	 */
	public java.util.Date getLastRefreshTime() {return lastRefreshTime;}
	
	/**
	 * 副本关卡次数刷新时间
	 */
	public DungeonLevel setLastRefreshTime(java.util.Date lastRefreshTime) {this.lastRefreshTime = lastRefreshTime;return this;}
	
	/**
	 * 总战斗次数
	 */
	public int getTotalFightCount() {return totalFightCount;}
	
	/**
	 * 总战斗次数
	 */
	public DungeonLevel setTotalFightCount(int totalFightCount) {this.totalFightCount = totalFightCount;return this;}
	
	
	// 代理
	private org.game.db.proxy.bean.DungeonLevelProxy dungeonLevelProxy = new org.game.db.proxy.bean.DungeonLevelProxy().build(this);
	
	public org.game.db.proxy.bean.DungeonLevelProxy getDungeonLevelProxy(){return dungeonLevelProxy;}
	
	
	protected Object[] getColumnNames(DataModelKeyEnum e){
		switch (e) {
		case SOURCE:
			return SOURCE_COLUMN_NAMES;
		case PINGYING:
			return PINGYING_COLUMN_NAMES;
		case HASHCODE:
			return HASHCODE_COLUMN_NAMES;
		case REMARKS:
			return SOURCE_COLUMN_REMARKS;
		default:
			return PINGYING_COLUMN_NAMES;
		}
	}
	
	protected Object[] getFKTableNames(DataModelKeyEnum e){
		switch (e) {
		case SOURCE:
			return FK_SOURCE_TABLE_NAMES;
		case PINGYING:
			return FK_PINGYING_TABLE_NAMES;
		case HASHCODE:
			return FK_HASHCODE_TABLE_NAMES;
		default:
			return FK_PINGYING_TABLE_NAMES;
		}
	}
	
	protected Object[] getFKColumnNames(DataModelKeyEnum e){
		switch (e) {
		case SOURCE:
			return FK_SOURCE_COLUMN_NAMES;
		case PINGYING:
			return FK_PINGYING_COLUMN_NAMES;
		case HASHCODE:
			return FK_HASHCODE_COLUMN_NAMES;
		default:
			return FK_PINGYING_TABLE_NAMES;
		}
	}
	
	protected String[] getBasicTypes(){
		return COLUMN_BASICTYPES;
	}
	
	protected Class[] getClassTypes(){
		return COLUMN_CLASSTYPES;
	}
	
	protected String[] getColumnTypes(){
		return COLUMN_COLUMNTYPES;
	}
	
	protected int getColumnCount(){
		return COLUMN_COUNT;
	}
	
	protected Object[] getColumeValues(){
		Object[] values = new Object[COLUMN_COUNT];
        values[0] = this.id;
        values[1] = this.playerId;
        values[2] = this.cid;
        values[3] = this.star;
        values[4] = this.createDate;
        values[5] = this.modifiedDate;
        values[6] = this.fightCount;
        values[7] = this.win;
        values[8] = this.achieveGoals;
        values[9] = this.lastRefreshTime;
        values[10] = this.totalFightCount;
        return values;
	}
	
	public DungeonLevel deepCopy(){
		DungeonLevel dungeonLevel = null;
		try {
			dungeonLevel = (DungeonLevel) super.clone();
		    dungeonLevel.setCreateDate(ToolCopy.copyObject(this.createDate));
		    dungeonLevel.setModifiedDate(ToolCopy.copyObject(this.modifiedDate));
		    dungeonLevel.setAchieveGoals(ToolCopy.copyObject(this.achieveGoals));
		    dungeonLevel.setLastRefreshTime(ToolCopy.copyObject(this.lastRefreshTime));
		    // 克隆索引
		    dungeonLevel.indexValues = ArrayUtils.clone(indexValues);
			return dungeonLevel;
		} catch (CloneNotSupportedException e) {
			e.printStackTrace();
		}
		return dungeonLevel;
	}
	
	
	protected Map<Object, Object> toMap(Object[] keys,Map<Object, Object> map){
        map.put(keys[0], this.id);
        map.put(keys[1], this.playerId);
        map.put(keys[2], this.cid);
        map.put(keys[3], this.star);
        map.put(keys[4], this.createDate);
        map.put(keys[5], this.modifiedDate);
        map.put(keys[6], this.fightCount);
        map.put(keys[7], this.win);
        map.put(keys[8], this.achieveGoals);
        map.put(keys[9], this.lastRefreshTime);
        map.put(keys[10], this.totalFightCount);
        return map;
    }
    
    protected DungeonLevel createForMap(Object[] keys,Map map){
   		this.id = (long)map.get(keys[0]);
   		this.playerId = (int)map.get(keys[1]);
   		this.cid = (int)map.get(keys[2]);
   		this.star = (int)map.get(keys[3]);
   		this.createDate = (java.util.Date)map.get(keys[4]);
   		this.modifiedDate = (java.util.Date)map.get(keys[5]);
   		this.fightCount = (int)map.get(keys[6]);
   		this.win = (boolean)map.get(keys[7]);
   		this.achieveGoals = (List)map.get(keys[8]);
   		this.lastRefreshTime = (java.util.Date)map.get(keys[9]);
   		this.totalFightCount = (int)map.get(keys[10]);
        return this;
    }
	
	
	protected JSONObject toJSONObject(Object[] keys,JSONObject obj){
        obj.put(keys[0], this.id);
        obj.put(keys[1], this.playerId);
        obj.put(keys[2], this.cid);
        obj.put(keys[3], this.star);
        obj.put(keys[4], this.createDate);
        obj.put(keys[5], this.modifiedDate);
        obj.put(keys[6], this.fightCount);
        obj.put(keys[7], this.win);
        obj.put(keys[8], toBytes(achieveGoals));
        obj.put(keys[9], this.lastRefreshTime);
        obj.put(keys[10], this.totalFightCount);
        return obj;
    }
    
    protected DungeonLevel createForJSONObject(Object[] keys,JSONObject obj){
	    this.id = obj.getLongValue(keys[0]);
	    this.playerId = obj.getIntValue(keys[1]);
	    this.cid = obj.getIntValue(keys[2]);
	    this.star = obj.getIntValue(keys[3]);
	    this.createDate = obj.getDate(keys[4]);
	    this.modifiedDate = obj.getDate(keys[5]);
	    this.fightCount = obj.getIntValue(keys[6]);
	    this.win = obj.getBooleanValue(keys[7]);
		this.achieveGoals = (List)forBytesObject(obj.getBytes(keys[8]));
	    this.lastRefreshTime = obj.getDate(keys[9]);
	    this.totalFightCount = obj.getIntValue(keys[10]);
        return this;
    }
    
    
    public DungeonLevel createForResultSet(ResultSet rs) throws SQLException{
	    this.id = rs.getLong(SOURCE_COLUMN_NAMES[0]);
	    this.playerId = rs.getInt(SOURCE_COLUMN_NAMES[1]);
	    this.cid = rs.getInt(SOURCE_COLUMN_NAMES[2]);
	    this.star = rs.getInt(SOURCE_COLUMN_NAMES[3]);
	    this.createDate = rs.getTimestamp(SOURCE_COLUMN_NAMES[4]);
	    this.modifiedDate = rs.getTimestamp(SOURCE_COLUMN_NAMES[5]);
	    this.fightCount = rs.getInt(SOURCE_COLUMN_NAMES[6]);
	    this.win = rs.getBoolean(SOURCE_COLUMN_NAMES[7]);
		this.achieveGoals = (List)forBytesObject(rs.getBytes(SOURCE_COLUMN_NAMES[8]));
	    this.lastRefreshTime = rs.getTimestamp(SOURCE_COLUMN_NAMES[9]);
	    this.totalFightCount = rs.getInt(SOURCE_COLUMN_NAMES[10]);
	    return this;
    }
    
    protected void writeBytes(IByteBuff byteBuf){
	    byteBuf.writeLong(this.id);
	    byteBuf.writeInt(this.playerId);
	    byteBuf.writeInt(this.cid);
	    byteBuf.writeInt(this.star);
	    byteBuf.writeDate(this.createDate);
	    byteBuf.writeDate(this.modifiedDate);
	    byteBuf.writeInt(this.fightCount);
	    byteBuf.writeBoolean(this.win);
	    byteBuf.writeObject(this.achieveGoals);
	    byteBuf.writeDate(this.lastRefreshTime);
	    byteBuf.writeInt(this.totalFightCount);
    }
	
	protected DungeonLevel readBytes(IByteBuff byteBuf){
	    this.id = byteBuf.readLong(null);
	    this.playerId = byteBuf.readInt(null);
	    this.cid = byteBuf.readInt(null);
	    this.star = byteBuf.readInt(null);
	    this.createDate = byteBuf.readDate(null);
	    this.modifiedDate = byteBuf.readDate(null);
	    this.fightCount = byteBuf.readInt(null);
	    this.win = byteBuf.readBoolean(null);
	    this.achieveGoals = (List)byteBuf.readObject();
	    this.lastRefreshTime = byteBuf.readDate(null);
	    this.totalFightCount = byteBuf.readInt(null);
	    return this;
	}
    
    
    protected JSONObject exportFKTableMap(Object[] keys,JSONObject map,DataModelKeyEnum e){
        return map;
    }
    
    protected boolean importFKTableMap(Object[] keys,JSONObject map,DataModelKeyEnum e){
		return true;
    }
    
	/** 取得[player]*/
	public Player getPlayerPkPlayerId(){
		return PlayerCache.me().getById(playerId);
	}
	
    /** 级联删除(延迟入库) */
    public boolean deleteAndSon(){
    	return false;
    }
    
    /** 级联删除(及时入库) */
    public boolean deleteAndSonAndFlush(){
    	return false;
    }
    
    /** 延迟插入数据库 */
    public DungeonLevel insert(){
    	return DungeonLevelCache.me().insert(this);
    }
    /** 延迟更新数据库 */
    public DungeonLevel update(){
    	return DungeonLevelCache.me().update(this);
    }
    /** 延迟删除数据库 */
    public boolean delete(){
    	return DungeonLevelCache.me().delete(this);
    }
    /** 即时插入数据库 */
    public DungeonLevel insertAndFlush(){
    	return DungeonLevelCache.me().insertAndFlush(this);
    }
    /** 即时更新数据库 */
    public DungeonLevel updateAndFlush(){
    	return DungeonLevelCache.me().updateAndFlush(this);
    }
    /** 即时删除数据库 */
    public boolean deleteAndFlush(){
    	return DungeonLevelCache.me().deleteAndFlush(this);
    }
    
    
	
	/**
	 * 同步索引值
	 */
	public DungeonLevel syncIndexValues(){
		indexValues[0] = SK_Plus.b(getId()).e();
		indexValues[1] = SK_Plus.b(getPlayerId()).e();
		return this;
	}
	/**
	 * 取得索引
	 */
	public String[] getIndexValues(){
		return indexValues;
	}
	
	protected Object getPrimaryKey(){
		return getId();
	}
	
	protected void setPrimaryKey(Object key){
		setId((long)key);
	}
//自定义内容起始位置
//自定义内容结束位置
}